using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

[Route("api/[controller]")]
[ApiController]
public class ProductionPlanningController : ControllerBase
{
    private readonly IProductionPlanningService _productionPlanningService;
    private readonly IWorkerHoursService _workerHoursService;
    private readonly IMachineToolService _machineToolService;

    public ProductionPlanningController(
        IProductionPlanningService productionPlanningService,
        IWorkerHoursService workerHoursService,
        IMachineToolService machineToolService)
    {
        _productionPlanningService = productionPlanningService;
        _workerHoursService = workerHoursService;
        _machineToolService = machineToolService;
    }

    /// <summary>
    /// 批量处理生产计划排程
    /// </summary>
    [HttpPost("BatchSchedule")]
    public async Task<IActionResult> BatchSchedule([FromBody] BatchScheduleRequest request)
    {
        try
        {
            var result = await _productionPlanningService.BatchScheduleAsync(request);
            return Ok(result);
        }
        catch (Exception ex)
        {
            return BadRequest(new { success = false, message = ex.Message });
        }
    }

    /// <summary>
    /// 获取工人工时数据
    /// </summary>
    [HttpPost("GetWorkerHours")]
    public async Task<IActionResult> GetWorkerHours([FromBody] WorkerHoursRequest request)
    {
        try
        {
            var result = await _workerHoursService.GetWorkerHoursAsync(request);
            return Ok(result);
        }
        catch (Exception ex)
        {
            return BadRequest(new { success = false, message = ex.Message });
        }
    }

    /// <summary>
    /// 获取机床数据
    /// </summary>
    [HttpPost("GetMachineTools")]
    public async Task<IActionResult> GetMachineTools([FromBody] MachineToolRequest request)
    {
        try
        {
            var result = await _machineToolService.GetMachineToolsAsync(request);
            return Ok(result);
        }
        catch (Exception ex)
        {
            return BadRequest(new { success = false, message = ex.Message });
        }
    }

    /// <summary>
    /// 获取成品信息
    /// </summary>
    [HttpGet("GetProductInfo/{taskId}")]
    public async Task<IActionResult> GetProductInfo(string taskId)
    {
        try
        {
            var result = await _productionPlanningService.GetProductInfoAsync(taskId);
            return Ok(result);
        }
        catch (Exception ex)
        {
            return BadRequest(new { success = false, message = ex.Message });
        }
    }
} 